package com.example.forum.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description: 配置自定义登录拦截器
 * User: DELL
 * Date: 2023-09-21
 * Time: 17:35
 */
@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器
        registry.addInterceptor(loginInterceptor)       // 添加⽤⼾登录拦截器
                .addPathPatterns("/**")                 // 拦截所有请求
                .excludePathPatterns("/sign-in.html")   // 排除登录 HTML
                .excludePathPatterns("/sign-up.html")   // 排除注册 HTML
                .excludePathPatterns("/user/login")     // 排除登录api接⼝
                .excludePathPatterns("/user/register")  // 排除注册api接⼝
                .excludePathPatterns("/user/logout")    // 排除退出api接⼝
                .excludePathPatterns("/swagger*/**")    // 排除登录swagger下所有
                .excludePathPatterns("/v3*/**")         // 排除登录v3下所有，swagger下产生测试接口的路径
                .excludePathPatterns("/dist/**")        // 排除所有静态⽂件
                .excludePathPatterns("/image/**")       // 排除 image 下所有
                .excludePathPatterns("/js/**")          // 排除 js 下所有
                .excludePathPatterns("/**.ico");        // 排除浏览器获取页面小图标的请求
    }
}
